//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.aidong.web.controller.member;

import com.aidong.cache.NameItem;
import com.aidong.dao.wills.BaosteelMemberDao;
import com.aidong.dao.wills.CardManyUserDao;
import com.aidong.dao.wills.CardTypeCodeDao;
import com.aidong.dao.wills.DicShopAreaCodeDao;
import com.aidong.dao.wills.MemberContractDao;
import com.aidong.dao.wills.PayBaosteelDao;
import com.aidong.dao.wills.SysUserDao;
import com.aidong.model.wills.BaosteelMember;
import com.aidong.model.wills.CardManyUser;
import com.aidong.model.wills.CardTypeCode;
import com.aidong.model.wills.DicShopCode;
import com.aidong.model.wills.GiftCard;
import com.aidong.model.wills.MemberCard;
import com.aidong.model.wills.MemberContract;
import com.aidong.model.wills.MemberEarnest;
import com.aidong.model.wills.MemberInfo;
import com.aidong.model.wills.PayBaosteel;
import com.aidong.model.wills.PayList;
import com.aidong.model.wills.PtContract;
import com.aidong.model.wills.Upload;
import com.aidong.service.BaosteelService;
import com.aidong.service.UploadService;
import com.aidong.util.FuncUtil;
import com.aidong.web.controller.member.PayController;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import org.json.JSONArray;
import org.json.JSONObject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping({"memberContractBaosteel"})
public class MemberContractBaosteelController extends PayController {
    @Resource
    MemberContractDao memberContractDao;
    @Resource
    CardTypeCodeDao cardTypeCodeDao;
    @Resource
    CardManyUserDao cardManyUserDao;
    @Resource
    DicShopAreaCodeDao dicShopAreaCodeDao;
    @Resource
    UploadService uploadService;
    @Resource
    SysUserDao sysUserDao;
    @Resource
    BaosteelMemberDao baosteelMemberDao;
    @Resource
    PayBaosteelDao payBaosteelDao;
    @Resource
    BaosteelService baosteelService;

    public MemberContractBaosteelController() {
    }

    @RequestMapping({"add"})
    public ModelAndView add() {
        List promotionList = this.promotionDao.getShopPromotionList(this.getLoginShopCode());
        ModelAndView mv = new ModelAndView("member/contract/add_baosteel");
        mv.addObject("promotionList", promotionList);
        mv.addObject("gender", this.getTypeList("gender"));
        mv.addObject("idType", this.getTypeList("idType"));
        mv.addObject("_picPath", this.getSetting("pic.path"));
        mv.addObject("_oper", "add");
        return mv;
    }

    @RequestMapping({"_add"})
    @ResponseBody
    public String _add(@ModelAttribute("contract") MemberContract contract, @RequestParam(value = "shops",required = false) String shops, @RequestParam("mbls") String mbls, @RequestParam("payls") String payls) {
        if(this.chkNull(contract.getSaleType())) {
            return this.getResult(false, "请选择销售类型");
        } else if(this.chkNull(contract.getCardType())) {
            return this.getResult(false, "请选择会籍类型");
        } else if(this.chkNull(contract.getFactPrice())) {
            return this.getResult(false, "请输入实际售价");
        } else {
            contract.setInAmount(Double.valueOf(0.0D));
            if(!"1".equals(contract.getSaleType())) {
                if(!"2".equals(contract.getSaleType()) && !"3".equals(contract.getSaleType())) {
                    return this.getResult(false, "销售类型错误");
                }

                if(this.chkNull(contract.getOldContractCode())) {
                    return this.getResult(false, "请输入原合同编号");
                }

                MemberContract cardType = this.memberContractDao.getByContractCode(contract.getOldContractCode());
                if(cardType == null) {
                    return this.getResult(false, "原合同编号错误");
                }

                if(cardType.getBeginTime() == null || cardType.getEndTime() == null || cardType.getStatus().intValue() != 1 || cardType.getEffectiveDate() != null || "8".equals(cardType.getSaleType())) {
                    return this.getResult(false, "原合同无效");
                }

                if("2".equals(contract.getSaleType())) {
                    if(cardType.getEndTime().getTime() < System.currentTimeMillis()) {
                        return this.getResult(false, "原合同已过有效期");
                    }

                    if(System.currentTimeMillis() - cardType.getBeginTime().getTime() < 2678400000L && contract.getStatus() != null && contract.getStatus().intValue() == 2) {
                        contract.setInAmount(cardType.getFactPrice());
                    } else {
                        double cardPrice;
                        if(cardType.getTotalCount().intValue() > 0) {
                            cardPrice = (double)Math.round((double)cardType.getRestCount().intValue() * cardType.getFactPrice().doubleValue() / (double)cardType.getTotalCount().intValue());
                        } else if(cardType.getBeginTime().getTime() > System.currentTimeMillis()) {
                            cardPrice = cardType.getFactPrice().doubleValue();
                        } else {
                            cardPrice = (double)Math.round((double)(cardType.getEndTime().getTime() - System.currentTimeMillis()) * cardType.getFactPrice().doubleValue() / (double)(cardType.getEndTime().getTime() - cardType.getBeginTime().getTime()));
                        }

                        if(cardPrice > cardType.getFactPrice().doubleValue()) {
                            cardPrice = cardType.getFactPrice().doubleValue();
                        }

                        contract.setInAmount(Double.valueOf(cardPrice > 0.0D?cardPrice:0.0D));
                    }
                }
            }

            CardTypeCode var23 = (CardTypeCode)this.cardTypeCodeDao.getById(contract.getCardType());
            if(var23 == null) {
                return this.getResult(false, "没有这个会籍类型");
            } else {
                Double var26 = null;
                if(!this.chkNullZ(contract.getEarnestId())) {
                    MemberEarnest fixedFee = (MemberEarnest)this.memberEarnestDao.getById(contract.getEarnestId());
                    if(fixedFee == null || fixedFee.getStatus().intValue() != 0 || !fixedFee.getShopCode().equalsIgnoreCase(this.getLoginShopCode())) {
                        return this.getResult(false, "定金不可用");
                    }

                    contract.setEarnestAmount(fixedFee.getEarnestAmount());
                    if(fixedFee.getOverDueUse().intValue() == 0 && var23.getCode().equalsIgnoreCase(fixedFee.getCardType())) {
                        var26 = fixedFee.getCardPrice();
                    }
                } else {
                    contract.setEarnestId((Integer)null);
                    contract.setEarnestAmount(Double.valueOf(0.0D));
                }

                if(this.chkNullZ(var26)) {
                    if((this.chkNullZ(contract.getPromotionId()) || this.chkNullZ(var23.getPromotionCard())) && (var23.getActiveTime().getTime() > System.currentTimeMillis() || var23.getInactiveTime().getTime() < System.currentTimeMillis())) {
                        return this.getResult(false, "会籍类型不在有效期");
                    }

                    Double var24 = this.cardTypeCodeDao.getCardTypeDiscount(contract.getCardType(), this.getLoginShopCode());
                    if(var24 == null) {
                        return this.getResult(false, "会籍类型不能在本店销售");
                    }

                    var26 = Double.valueOf(var23.getPrice().doubleValue() * var24.doubleValue());
                }

                if(!this.equals(contract.getCardPrice().doubleValue(), var26.doubleValue())) {
                    return this.getResult(false, "卡价格不符");
                } else {
                    contract.setShopCode(this.getLoginShopCode());
                    contract.setSaleDate(new Date());
                    if(var23.getAddValids().intValue() > 0) {
                        Calendar var25 = Calendar.getInstance();
                        var25.setTime(contract.getEndTime());
                        if("01".equals(var23.getAddValidUnit())) {
                            var25.add(5, var23.getAddValids().intValue());
                        } else if("02".equals(var23.getAddValidUnit())) {
                            var25.add(5, var23.getAddValids().intValue() * 7);
                        }

                        if("03".equals(var23.getAddValidUnit())) {
                            var25.add(2, var23.getAddValids().intValue());
                        }

                        if("04".equals(var23.getAddValidUnit())) {
                            var25.add(1, var23.getAddValids().intValue());
                        }

                        contract.setNewEndTime(var25.getTime());
                    }

                    contract.setTotalCount(var23.getDegree());
                    contract.setRestCount(var23.getDegree());
                    contract.setManyShop(var23.getManyShop());
                    contract.setValids(var23.getValids());
                    contract.setValidUnit(var23.getValidUnit());
                    contract.setAddValids(var23.getAddValids());
                    contract.setAddValidUnit(var23.getAddValidUnit());
                    contract.setAddFee(Double.valueOf(0.0D));
                    contract.setStopFee(var23.getStopFee());
                    contract.setChangeFee(var23.getChangeFee());
                    contract.setMendFee(var23.getMendFee());
                    contract.setChgShopFee(var23.getChgShopFee());
                    contract.setContDiscount(var23.getContDiscount());
                    contract.setStatus(Integer.valueOf(this.equals(contract.getFactPrice().doubleValue(), contract.getTotalPrice().doubleValue())?1:2));
                    contract.setCommissionDate(new Date());
                    contract.setReceivePaper(Integer.valueOf(0));
                    contract.setBarcodeTasteContract(Integer.valueOf(0));
                    contract.setSignStatus(Integer.valueOf(this.chkNullZ(contract.getSignStatus())?2:0));
                    contract.setPrintLabel(Integer.valueOf(0));
                    contract.setCreateUser(this.getLoginUserCode());
                    contract.setCreateTime(new Date());
                    contract.setUpdateTime(new Date());
                    contract.setReviewStatus(Integer.valueOf(1));
                    if(!this.chkNull(var23.getGiftCardType()) && contract.getStatus().intValue() == 1 && !this.chkNull(contract.getGiftCardCode())) {
                        NameItem var27 = this.cache.getNameItem("giftCardType", var23.getGiftCardType());
                        if(var27 != null) {
                            contract.setGiftCardType(var27.getId());
                            if(contract.getGiftCardCode().length() <= 6) {
                                contract.setGiftCardCode("9900119000100" + contract.getGiftCardCode());
                            }

                            contract.setGiftCardAmount(this.parseDouble(var27.getProp()));
                            GiftCard giftCard = this.giftCardDao.getByCardCode(contract.getGiftCardCode());
                            if(giftCard == null || !giftCard.getShopCode().equalsIgnoreCase(contract.getShopCode())) {
                                return this.getResult(false, "没有这个储值卡号");
                            }

                            if(giftCard.getStatus().intValue() != 1) {
                                return this.getResult(false, "储值卡号已使用,请选择其他卡号");
                            }

                            if(giftCard.getReportLoss().intValue() == 1) {
                                return this.getResult(false, "储值卡号已挂失,请选择其他卡号");
                            }

                            if(!giftCard.getCardType().equalsIgnoreCase(contract.getGiftCardType())) {
                                return this.getResult(false, "储值卡类型不符,请选择其他卡号");
                            }
                        }
                    }

                    double var28 = 0.0D;
                    if(contract.getGiftCardAmount() != null) {
                        var28 += contract.getGiftCardAmount().doubleValue();
                    }

                    if(var23.getAmortizeFee2() != null) {
                        var28 += var23.getAmortizeFee2().doubleValue();
                    }

                    if(var23.getAmortizeFee3() != null) {
                        var28 += var23.getAmortizeFee3().doubleValue();
                    }

                    if(var23.getAmortizeFee4() != null) {
                        var28 += var23.getAmortizeFee4().doubleValue();
                    }

                    contract.setFixedFee(Double.valueOf(var28));
                    double giftFee = 0.0D;
                    if(contract.getGiftCardAmount() != null) {
                        giftFee += contract.getGiftCardAmount().doubleValue();
                    }

                    if(var23.getAmortizeFee2() != null) {
                        giftFee += var23.getAmortizeFee2().doubleValue();
                    }

                    if(var23.getAmortizeFee3() != null) {
                        giftFee += var23.getAmortizeFee3().doubleValue();
                    }

                    if(var23.getAmortizeFee4() != null) {
                        giftFee += var23.getAmortizeFee4().doubleValue();
                    }

                    if(giftFee > 0.0D) {
                        DecimalFormat shopList = new DecimalFormat("0.##");
                        StringBuilder memberList = new StringBuilder();
                        memberList.append("上述会费还包含价值人民币" + shopList.format(giftFee) + "元的礼包，含：" + (this.chkNullZ(contract.getGiftCardAmount())?"---":shopList.format(contract.getGiftCardAmount())) + "元的威尔士礼品卡，" + (this.chkNullZ(var23.getAmortizeFee4())?"---":shopList.format(var23.getAmortizeFee4())) + "元的赠品，" + (this.chkNullZ(var23.getAmortizeFee2())?"---":shopList.format(var23.getAmortizeFee2())) + "元的健身计划，" + (this.chkNullZ(var23.getAmortizeFee3())?"---":shopList.format(var23.getAmortizeFee3())) + "元的PT课程。");
                        contract.setGiftNote(memberList.toString());
                    }

                    ArrayList var29 = new ArrayList();
                    if(!this.chkNull(shops)) {
                        String[] var30 = shops.split(",");
                        String[] member = var30;
                        int payList = var30.length;

                        for(int payMsg = 0; payMsg < payList; ++payMsg) {
                            String pay = member[payMsg];
                            if(!this.chkNull(pay)) {
                                var29.add(pay.trim());
                            }
                        }
                    }

                    ArrayList var31 = new ArrayList();
                    MemberInfo var32 = this.getMemberList(mbls, var31);
                    if(var32 == null) {
                        return this.getResult(false, "会员信息错误");
                    } else {
                        Iterator var33 = var31.iterator();

                        MemberInfo var35;
                        do {
                            if(!var33.hasNext()) {
                                contract.setCardCode(var32.getCardCode());
                                ArrayList var34 = new ArrayList();
                                StringBuilder var36 = new StringBuilder();
                                PayList var39 = this.getPayList(payls, var34, "01", var36);
                                if(var39 == null) {
                                    return this.getResult(false, var36.toString());
                                }

                                if(!this.equals(var39.getAmount().doubleValue(), contract.getPayAmount().doubleValue())) {
                                    return this.getResult(false, "付款金额不一致");
                                }

                                contract.setSalesCode(var39.getSalesCode());
                                contract.setSalesCode2(var39.getSalesCode2());

                                try {
                                    this.memberContractDao.addContract(contract, var29, var31, var34);
                                    String var40 = !this.chkNull(contract.getGiftCardType()) && !this.chkNull(contract.getGiftCardCode())?"5":"1";
                                    this.smsListService.addSmsList(var40 + contract.getSaleType(), contract.getSaleId().intValue());
                                    this.addUserLog("会籍合同销售", "合同号:" + contract.getContractCode() + ",会员:" + contract.getMemberCode());
                                    if("1".equals(contract.getSaleType()) && var23.getPresentPt() != null && var23.getPresentPt().intValue() == 1) {
                                        PtContract ptContract = new PtContract();
                                        ptContract.setShopCode(this.getLoginShopCode());
                                        ptContract.setMemberCode(contract.getMemberCode());
                                        ptContract.setEarnestId((Integer)null);
                                        ptContract.setPromotionId((Integer)null);
                                        ptContract.setEarnestAmount(Double.valueOf(0.0D));
                                        ptContract.setSaleType("1");
                                        ptContract.setSaleDate(new Date());
                                        ptContract.setPtCode("ZPT001");
                                        ptContract.setCoachCode("wills");
                                        ptContract.setQuantity(Integer.valueOf(1));
                                        ptContract.setFactPrice(Double.valueOf(0.0D));
                                        ptContract.setPayAmount(Double.valueOf(0.0D));
                                        ptContract.setBeginTime(this.getTrimDate(new Date()));
                                        Calendar cal = Calendar.getInstance();
                                        cal.setTime(ptContract.getBeginTime());
                                        cal.add(5, 7);
                                        ptContract.setEndTime(cal.getTime());
                                        ptContract.setBespeakQuantity(Integer.valueOf(0));
                                        ptContract.setClearQuantity(Integer.valueOf(0));
                                        ptContract.setInAmount(Double.valueOf(0.0D));
                                        ptContract.setStatus(Integer.valueOf(1));
                                        ptContract.setCommissionDate(new Date());
                                        ptContract.setReceivePaper(Integer.valueOf(0));
                                        ptContract.setSignStatus(Integer.valueOf(2));
                                        ptContract.setPrintLabel(Integer.valueOf(0));
                                        ptContract.setSaleClassify("3");
                                        ptContract.setSalesCode("wills");
                                        ptContract.setSalesCode2("");
                                        ptContract.setCreateUser(this.getLoginUserCode());
                                        ptContract.setCreateTime(new Date());
                                        ptContract.setUpdateTime(new Date());
                                        ptContract.setReviewStatus(Integer.valueOf(1));

                                        try {
                                            this.ptContractDao.addContract(ptContract, new ArrayList());
                                        } catch (Exception var21) {
                                            this.log.error("add membercontract ptcontract", var21);
                                        }
                                    }
                                } catch (Exception var22) {
                                    this.log.error("add membercontract", var22);
                                    return this.getResult(false, "保存发生错误");
                                }

                                return this.getResult(true, "保存完成");
                            }

                            var35 = (MemberInfo)var33.next();
                            if(this.memberBlackListDao.chkExists(var32.getIdType(), var32.getIdNumber())) {
                                return this.getFail(-8, "证件号在黑名单中，不能办理合同");
                            }

                            if(var35.getStatus().intValue() == 1) {
                                if(this.chkNull(var35.getCardCode())) {
                                    return this.getResult(false, "会员卡号错误");
                                }

                                MemberCard var37 = this.memberCardDao.getById(var35.getCardCode());
                                if(var37 == null || !var37.getShopCode().equalsIgnoreCase(this.getLoginShopCode()) || var37.getStatus().intValue() != 1) {
                                    return this.getResult(false, "会员卡号错误");
                                }
                            }

                            if(this.chkNull(var35.getMemberCode())) {
                                MemberInfo var38 = this.memberInfoDao.getByIdNumber(var35.getIdType(), var35.getIdNumber());
                                if(var38 != null) {
                                    MemberContract e = this.memberContractDao.getCurrentByMemberCode(var38.getMemberCode());
                                    if(e != null) {
                                        return this.getResult(false, "签订合同的证件号已存在有效合同");
                                    }

                                    if(!var35.getChName().equalsIgnoreCase(var38.getChName())) {
                                        return this.getResult(false, "姓名和证件号不一致和原有会员信息不一致");
                                    }

                                    var35.setMemberCode(var38.getMemberCode());
                                }
                            }
                        } while(this.chkNull(var35.getMemberCode()) || !"1".equals(contract.getSaleType()) || this.memberContractDao.getFirstDateByMemberCode(var35.getMemberCode()) == null);

                        return this.getResult(false, "会员已有合同,请按续会购买");
                    }
                }
            }
        }
    }

    @RequestMapping({"getCardTypeList"})
    @ResponseBody
    public String getCardTypeList(@RequestParam("saleType") Integer saleType, @RequestParam("op") String op) {
        int option = 0;
        if(!this.chkNull(op) && op.indexOf("r") >= 0) {
            ++option;
        }

        option += 4;
        List list = this.cardTypeCodeDao.getShopCardTypeList(this.getLoginShopCode(), saleType.intValue(), option);
        StringBuilder sb = new StringBuilder();
        sb.append("[");

        CardTypeCode cardType;
        for(Iterator i$ = list.iterator(); i$.hasNext(); sb.append("{code:\"").append(cardType.getCode()).append("\"").append(",name:\"").append(cardType.getChName()).append("\"").append("}")) {
            cardType = (CardTypeCode)i$.next();
            if(sb.length() > 5) {
                sb.append(",");
            }
        }

        sb.append("]");
        return this.getSuccess(sb.toString(), "");
    }

    @RequestMapping({"getCardType"})
    @ResponseBody
    public String getCardType(@RequestParam("code") String code, @RequestParam(value = "pmId",required = false) Integer pmId, @RequestParam(value = "earnestId",required = false) Integer earnestId) {
        CardTypeCode cardType = (CardTypeCode)this.cardTypeCodeDao.getById(code);
        if(cardType == null) {
            return this.getResult(false, "没有这个卡种");
        } else {
            Double cardPrice = null;
            if(!this.chkNullZ(earnestId)) {
                MemberEarnest pnum = (MemberEarnest)this.memberEarnestDao.getById(earnestId);
                if(pnum == null || pnum.getStatus().intValue() != 0 || !"1".equals(pnum.getEarnestType()) || !pnum.getShopCode().equalsIgnoreCase(this.getLoginShopCode())) {
                    return this.getResult(false, "没有这个定金");
                }

                if(pnum.getOverDueUse().intValue() == 0 && cardType.getCode().equalsIgnoreCase(pnum.getCardType())) {
                    cardPrice = pnum.getCardPrice();
                }
            }

            if(this.chkNullZ(cardPrice)) {
                if((this.chkNullZ(pmId) || this.chkNullZ(cardType.getPromotionCard())) && (cardType.getActiveTime().getTime() > System.currentTimeMillis() || cardType.getInactiveTime().getTime() < System.currentTimeMillis())) {
                    return this.getResult(false, "不在有效期");
                }

                Double var13 = this.cardTypeCodeDao.getCardTypeDiscount(code, this.getLoginShopCode());
                if(var13 == null) {
                    return this.getResult(false, "不能在本店销售");
                }

                cardPrice = Double.valueOf(cardType.getPrice().doubleValue() * var13.doubleValue());
            }

            int var14 = 1;
            if(cardType.getManyUser().intValue() == 1) {
                List giftCard = this.cardManyUserDao.getCardManyUserList(code);
                var14 = 0;

                CardManyUser shopList;
                for(Iterator sb = giftCard.iterator(); sb.hasNext(); var14 += shopList.getUseQuantity().intValue()) {
                    shopList = (CardManyUser)sb.next();
                }
            }

            NameItem var15 = null;
            if(!this.chkNull(cardType.getGiftCardType())) {
                var15 = this.cache.getNameItem("giftCardType", cardType.getGiftCardType());
            }

            StringBuilder var16 = new StringBuilder();
            var16.append("{code:\"").append(cardType.getCode()).append("\"").append(",name:\"").append(cardType.getChName()).append("\"").append(",valids:").append(cardType.getValids()).append("").append(",validUnit:\"").append(cardType.getValidUnit()).append("\"").append(",valid:\"").append(cardType.getValids() + this.nvl(this.cache.getValue("timeUnit", cardType.getValidUnit()))).append("\"").append(",addValids:").append(cardType.getAddValids()).append("").append(",addValidUnit:\"").append(cardType.getAddValidUnit()).append("\"").append(",addValid:\"").append(cardType.getAddValids() + this.nvl(this.cache.getValue("timeUnit", cardType.getAddValidUnit()))).append("\"").append(",openPeriod:").append(cardType.getOpenPeriod()).append("").append(",cardPrice:").append(cardPrice).append("").append(",userNum:").append(var14).append("").append(",giftCardType:\"").append(var15 == null?"":var15.getId()).append("\"").append(",giftCardName:\"").append(var15 == null?"":var15.getName()).append("\"").append(",giftCardAmount:\"").append(var15 == null?"":var15.getProp()).append("\"").append(",manyShop:\"").append(this.nvl(cardType.getManyShop()).trim()).append("\"").append(",manyShopQuantity:").append(cardType.getManyShopQuantity()).append("").append(",shopList:[");
            if(!this.chkNull(cardType.getManyShop())) {
                List var17 = this.dicShopAreaCodeDao.getAreaShopList(cardType.getManyShop(), false);
                int sn = 0;
                Iterator i$ = var17.iterator();

                while(i$.hasNext()) {
                    DicShopCode shop = (DicShopCode)i$.next();
                    if(shop.getStatus().intValue() == 1) {
                        if(sn++ > 0) {
                            var16.append(",");
                        }

                        var16.append("{code:\"").append(shop.getCode()).append("\"").append(",name:\"").append(shop.getChName()).append("\"").append("}");
                    }
                }
            }

            var16.append("]}");
            return this.getSuccess(var16.toString(), "");
        }
    }

    @RequestMapping({"getIdNumberChk"})
    @ResponseBody
    public String getIdNumberChk(@RequestParam("idt") String idType, @RequestParam("idn") String idNumber) {
        if(this.memberBlackListDao.chkExists(idType, idNumber)) {
            return this.getFail(-8, "证件号在黑名单中，不能办理");
        } else {
            MemberInfo member = this.memberInfoDao.getByIdNumber(idType, idNumber);
            if(member != null) {
                MemberContract contract = this.memberContractDao.getCurrentByMemberCode(member.getMemberCode());
                if(contract != null) {
                    return this.getResult(false, "签订合同的证件号已存在有效合同");
                }
            }

            return this.getResult(true, "");
        }
    }

    protected MemberInfo getMemberList(String mbls, List<MemberInfo> memberList) {
        MemberInfo memberInfo = null;
        String[] ss = mbls.split("\\|");

        for(int i = 0; i < ss.length; ++i) {
            String[] s1 = ss[i].split(",");
            MemberInfo member;
            if(!this.chkNull(s1[0])) {
                member = this.memberInfoDao.getById(s1[0]);
                if(member == null) {
                    return null;
                }

                member.setStatus(Integer.valueOf(0));
                if(this.chkNull(member.getCardCode()) || !s1[1].equalsIgnoreCase(member.getCardCode())) {
                    member.setCardCode(s1[1]);
                    member.setStatus(Integer.valueOf(1));
                }

                member.setMemberPhoto(s1[7]);
                member.setIdCardPhoto(s1[8]);
                member.setMobile(s1[6]);
            } else {
                member = new MemberInfo();
                member.setMemberSource("01");
                member.setShopCode(this.getLoginShopCode());
                member.setCardCode(s1[1]);
                member.setChName(s1[2]);
                member.setGender(s1[3]);
                member.setIdType(s1[4]);
                member.setIdNumber(s1[5]);
                member.setMobile(s1[6]);
                member.setMemberPhoto(s1[7]);
                member.setIdCardPhoto(s1[8]);
                member.setStatus(Integer.valueOf(1));
                member.setCreateUser(this.getLoginUserCode());
                member.setCreateTime(new Date());
                member.setUpdateTime(new Date());
            }

            memberList.add(member);
            if(memberInfo == null && s1.length > 9 && "1".equals(s1[9])) {
                memberInfo = member;
            }
        }

        if(memberInfo == null && memberList.size() > 0) {
            memberInfo = (MemberInfo)memberList.get(0);
        }

        return memberInfo;
    }

    @RequestMapping({"upload"})
    public ModelAndView upload(@RequestParam(value = "tp",required = false) Integer tp) {
        String sn = !this.chkNullZ(tp) && tp.intValue() == 2?"2":"";
        ModelAndView mv = new ModelAndView("member/contract/upload" + sn);
        mv.addObject("_picPath", this.getSetting("pic.path"));
        mv.addObject("_oper", "add");
        return mv;
    }

    @RequestMapping({"_upload"})
    @ResponseBody
    public String _upload(@RequestParam("file") MultipartFile file) {
        StringBuilder msg = new StringBuilder();
        Upload upload = this.uploadService.upload(file, msg);
        return upload == null?this.getUploadResult(false, msg.toString()):this.getUploadSuccess("{\"fid\":" + upload.getFileId() + ",\"furl\":\"" + upload.getUrl() + "\"}", "上传成功");
    }

    @RequestMapping({"mobileVerify"})
    @ResponseBody
    public String mobileVerify(@RequestParam("mobile") String mobile, HttpServletRequest request) {
        if(this.chkNull(mobile)) {
            return this.getResult(false, "手机号码错误");
        } else {
            BaosteelMember baosteelMember = (BaosteelMember)this.baosteelMemberDao.getById(mobile);
            if(baosteelMember == null) {
                return this.getResult(false, "不是宝钢会员");
            } else {
                String code = FuncUtil.getRandNumStr(6);
                if(this.smsListService.sendVerify(mobile, code)) {
                    request.getSession().setAttribute("verifyMobile", mobile);
                    request.getSession().setAttribute("verifyCode", code);
                    return this.getResult(true, "发送成功");
                } else {
                    return this.getResult(false, "发送失败");
                }
            }
        }
    }

    @RequestMapping({"_mobileVerify"})
    @ResponseBody
    public String _mobileVerify(@RequestParam("mobile") String mobile, @RequestParam("code") String code, HttpServletRequest request) {
        if(this.chkNull(mobile)) {
            return this.getResult(false, "手机号码错误");
        } else {
            BaosteelMember baosteelMember = (BaosteelMember)this.baosteelMemberDao.getById(mobile);
            if(baosteelMember == null) {
                return this.getResult(false, "不是宝钢会员");
            } else {
                String mobile1 = (String)request.getSession().getAttribute("verifyMobile");
                if(mobile1 != null && mobile1.equalsIgnoreCase(mobile)) {
                    String code1 = (String)request.getSession().getAttribute("verifyCode");
                    if(code1 != null && code1.equalsIgnoreCase(code)) {
                        request.getSession().setAttribute("verifyMobile_" + mobile, "1");
                        return this.getSuccess("{\"mobile\":\"" + mobile + "\",\"memberCode\":\"" + this.nvl(baosteelMember.getMemberCode()) + "\"}", "验证成功");
                    } else {
                        return this.getResult(false, "验证码输入错误");
                    }
                } else {
                    return this.getResult(false, "手机号码错误");
                }
            }
        }
    }

    protected String getUploadSuccess(String data, String msg) {
        return "{\"ret\":true, \"success\":true, \"data\":" + data + ", \"msg\":\"" + this.convStr(msg) + "\"}";
    }

    protected String getUploadResult(boolean ret, String msg) {
        return "{\"ret\":" + (ret?"true":"false") + ", \"success\":" + (ret?"true":"false") + ", \"msg\":\"" + this.convStr(msg) + "\"}";
    }

    @RequestMapping({"_getBsPay"})
    @ResponseBody
    public String _getBsPay(@RequestParam("mobile") String mobile, @RequestParam("money") Double money, @RequestParam String cardType, @RequestParam Double price) {
        if(this.chkNullZ(money)) {
            return this.getResult(false, "付款金额错误");
        } else {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
            SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            DecimalFormat nf = new DecimalFormat("0.##");
            String shopCode = this.getLoginShopCode();
            Date tradeDate = new Date();
            String tradeNo = shopCode + sdf.format(tradeDate);
            String serialNo = System.currentTimeMillis() / 1000L / 60L / 60L - 400000L + FuncUtil.getRandNumStr(4);
            if(this.chkNullZ(price)) {
                price = money;
            }

            CardTypeCode cardTypeCode = (CardTypeCode)this.cardTypeCodeDao.getById(cardType);
            String detail = this.getPaybsDetail(cardTypeCode.getCode(), cardTypeCode.getChName(), nf.format(price));
            StringBuilder needPwd = new StringBuilder();
            StringBuilder msg = new StringBuilder();
            if(this.baosteelService.createPay(mobile, nf.format(money), tradeNo, serialNo, detail, nf.format(price), sdf2.format(tradeDate), needPwd, msg)) {
                PayBaosteel payBs = new PayBaosteel();
                payBs.setShopCode(shopCode);
                payBs.setTradeNo(tradeNo);
                payBs.setSerialNo(serialNo);
                payBs.setPayUser(mobile);
                payBs.setAmount(money);
                payBs.setNeedPwd(Integer.valueOf("1".equals(needPwd.toString())?1:0));
                payBs.setStatus(Integer.valueOf(0));
                payBs.setNote(msg.toString());
                payBs.setCreateUser(this.getLoginUserCode());
                payBs.setCreateTime(new Date());
                payBs.setUpdateTime(new Date());

                try {
                    this.payBaosteelDao.add(payBs);
                    this.addUserLog("新增宝钢付款", "编号:" + payBs.getAutoId() + ",帐号:" + payBs.getPayUser());
                    return this.getSuccess(this.getPayBsJson(payBs), "提交成功");
                } catch (Exception var18) {
                    this.log.error("add paybaosteel", var18);
                    return this.getResult(false, "保存宝钢支付发生错误");
                }
            } else {
                return this.getResult(false, msg.toString());
            }
        }
    }

    @RequestMapping({"_getBsPayOk"})
    @ResponseBody
    public String _getBsPayOk(@RequestParam Integer payId, @RequestParam String smsCode, @RequestParam(required = false) String payPwd) {
        PayBaosteel payBs = (PayBaosteel)this.payBaosteelDao.getById(payId);
        if(payBs == null) {
            return this.getResult(false, "付款信息错误");
        } else {
            SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            DecimalFormat nf = new DecimalFormat("0.##");
            StringBuilder msg = new StringBuilder();
            if(this.baosteelService.doPay(payBs.getPayUser(), nf.format(payBs.getAmount()), smsCode, payPwd, payBs.getTradeNo(), payBs.getSerialNo(), sdf2.format(payBs.getCreateTime()), msg)) {
                payBs.setStatus(Integer.valueOf(1));
                payBs.setNote(msg.toString());
                payBs.setPayTime(new Date());
                this.payBaosteelDao.updatePayStatus(payBs);
                return this.getSuccess(this.getPayBsJson(payBs), "支付成功");
            } else {
                return this.getResult(false, msg.toString());
            }
        }
    }

    private String getPayBsJson(PayBaosteel payBs) {
        return "{payId:" + payBs.getAutoId() + ",mobile:\"" + payBs.getPayUser() + "\",amount:" + payBs.getAmount() + ",needPwd:" + payBs.getNeedPwd() + ",status:" + payBs.getStatus() + "}";
    }

    private String getPaybsDetail(String code, String name, String price) {
        JSONArray array = new JSONArray();

        try {
            JSONObject e = new JSONObject();
            e.put("code", code);
            e.put("goods", name);
            e.put("number", 1);
            e.put("price", price);
            e.put("category", "001");
            e.put("amount", price);
            e.put("tax", "0");
            array.put(e);
        } catch (Exception var6) {
            this.log.error(var6);
        }

        return array.toString();
    }
}
